package com.example.pc.underlinetextview;

import android.graphics.Color;
import android.graphics.Paint;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Html;
import android.text.SpannableString;
import android.text.style.UnderlineSpan;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    TextView mTv1,mTv2,mTv3;
    UnderLineTextView mUnderlineTv;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //初始化控件
        mTv1= (TextView) findViewById(R.id.tv1);
        mTv2= (TextView) findViewById(R.id.tv2);
        mTv3= (TextView) findViewById(R.id.tv3);
        mUnderlineTv= (UnderLineTextView) findViewById(R.id.tv4);

        //三种方法添加下划线,下划线与字体颜色一致，无法单独改变下划线的颜色
        mTv1.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
        mTv2.setText(Html.fromHtml("<u>"+"underline2"+"<u/>"));
        String text="underline3";
        SpannableString content = new SpannableString(text);
        content.setSpan(new UnderlineSpan(), 0, text.length(), 0);
        mTv3.setText(content);

        //自定义view单独改变下划线颜色
        /*mUnderlineTv.setUnderLineColor(Color.RED);
        mUnderlineTv.setmUnderlineWidth(2);*/
    }
}
